import { IPSAppView } from '../../app/view/ipsapp-view';
import { IPSControl } from '../ipscontrol';
import { IPSDBViewPortletPart } from './ipsdbview-portlet-part';
import { PSDBSysPortletPartImpl } from './psdbsys-portlet-part-impl';

export class PSDBViewPortletPartImpl extends PSDBSysPortletPartImpl implements IPSDBViewPortletPart {
  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.findPSControl(value);
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  protected portletpsappview: IPSAppView | null = null;

  getPortletPSAppView(): IPSAppView | null {
    if (this.portletpsappview != null) return this.portletpsappview;
    const value = this.M.getPortletPSAppView;
    if (value == null) {
      return null;
    }
    this.portletpsappview = this.getPSModel4('app.view.IPSAppView', value, 'getPortletPSAppView') as IPSAppView;
    return this.portletpsappview;
  }

  get portletPSAppView(): IPSAppView | null {
    return this.getPortletPSAppView();
  }

  getPortletPSAppViewMust(): IPSAppView {
    const value = this.getPortletPSAppView();
    if (value == null) {
      throw new Error('未指定嵌入视图对象');
    }
    return value;
  }

  get cls(): string {
    return 'PSDBViewPortletPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.dashboard.IPSDBAppViewPortletPart' || cls == 'control.dashboard.IPSDBViewPortletPart') return true;
    return super.instanceof(cls);
  }
}
